package com.itheima.mall.controller.smsController;


import com.itheima.mall.commons.R;
import com.itheima.mall.service.smsService.SmsFlashPromotionService;
import com.itheima.pojo.sms.SmsFlashPromotion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@CrossOrigin
@RestController
@RequestMapping("flash")
public class SmsFlashPromotionController {
    @Autowired
    private SmsFlashPromotionService smsFlashPromotionService;

    /**
     * 活动添加
     */
    @PostMapping("create")
    private R flashCreate(@RequestBody Map<String, Object> map) {
        smsFlashPromotionService.saved(map);
        return R.ok(null);
    }
    /**
     * 删除活动
     */
    @PostMapping("delete/{id}")
    private R deleteFlash(@PathVariable Integer id) {
        smsFlashPromotionService.deleteFlash(id);
        return R.ok(null);
    }
    /**
     * 根据活动名称分页查询
     */
    @GetMapping("list")
    private R listFlash(String keyword, Integer pageNum, Integer pageSize){
        return smsFlashPromotionService.listFlash(keyword,pageNum,pageSize);
    }
    /**
     * 修改上下线状态
     */
    @PostMapping("update/status/{id}")
    private R updateStatus(@PathVariable(required = true) Integer id, Integer status){
        return smsFlashPromotionService.updateStatus(id,status);
    }
    /**
     * 编辑活动
     */
    @PostMapping("update/{id}")
    private R updateFlashId(@PathVariable(required = true)Integer id ,@RequestBody SmsFlashPromotion smsFlashPromotion){
        return smsFlashPromotionService.updateFlashId(id,smsFlashPromotion);
    }
    /**
     *获取活动详情
     */
    @GetMapping("/{id}")
    private R getFlash(@PathVariable(required = true)Integer id){
        return smsFlashPromotionService.getFlash(id);
    }


}
